package com.fakeofarty;

import android.text.format.Time;

public class DistanceData {

	private int mTrackSeconds;
	private int mTrackMinuts;
	private int mTrackHours;
	private int mMinuts;
	private int mHours;
	private int mMeters;
	private int mKilometers;
	private int mTotalMeters;
	private int mTotalKilometers;
	private int mPreviousMeters;
	private int mPreviousKilometers;
	private int mPointNumber;
	private int mSpeedKilometers;
	private int mSpeedRemnat;
	private boolean mGpsStatus;
	private int mState;
	private int mBatteryLevel;

	private String getIntWithZero(int number, int length) {
		String result = "";
		for (int i = length; i > 1; i--) {
			if (number < Math.pow(10, i - 1)) {
				result += "0";
			} else
				break;
		}
		result += number;
		return result;
	}

	public DistanceData(long time, float distance, float totalDistance,
			float previousDistance, int pointNumber, float speed,
			boolean gpsStatus, int state, int batteryLevel) {

		mTrackSeconds = (int) (time / 1000);
		mTrackMinuts = mTrackSeconds / 60;
		mTrackHours = mTrackMinuts / 60;
		mTrackMinuts = mTrackMinuts % 60;
		mTrackSeconds = mTrackSeconds % 60;

		mMeters = (int) Math.floor(distance) % 1000;
		mKilometers = (int) Math.floor(distance / 1000);
		mTotalMeters = (int) Math.floor(totalDistance) % 1000;
		mTotalKilometers = (int) Math.floor(totalDistance / 1000);
		mPreviousMeters = (int) Math.floor(previousDistance) % 1000;
		mPreviousKilometers = (int) Math.floor(previousDistance / 1000);
		mPointNumber = pointNumber;
		mSpeedKilometers = (int) Math.floor(speed * 60 * 60 / 1000);
		mSpeedRemnat = (int) Math.floor(speed * 60 * 60 / 1000 * 10) % 10;
		mGpsStatus = gpsStatus;
		mState = state;

		Time time_real = new Time();
		time_real.setToNow();
		mMinuts = time_real.minute;
		mHours = time_real.hour;

		mBatteryLevel = batteryLevel;

	}

	public String getTrackTime() {
		return "" + mTrackHours + ":" + getIntWithZero(mTrackMinuts, 2) + ":"
				+ getIntWithZero(mTrackSeconds, 2);
	}

	public String getTrackTimeShort() {
		return "" + mTrackHours + ":" + getIntWithZero(mTrackMinuts, 2);
	}

	public String getTimeShort() {
		return "" + mHours + ":" + getIntWithZero(mMinuts, 2);
	}

	public String getDistance() {
		if (mKilometers > 0)
			return "" + mKilometers + "." + getIntWithZero(mMeters, 3);
		return "" + mMeters;
	}

	public String getDistanceShort() {
		if (mKilometers > 0)
			return "" + mKilometers + "." + getIntWithZero(mMeters / 10, 2);
		return "" + mMeters / 10;
	}

	public String getTotalDistance() {
		if (mTotalKilometers > 0)
			return "" + mTotalKilometers + "."
					+ getIntWithZero(mTotalMeters, 3);
		return "" + mTotalMeters;
	}

	public String getTotalDistanceShort() {
		if (mTotalKilometers > 0)
			return "" + mTotalKilometers + "."
					+ getIntWithZero(mTotalMeters / 10, 2);
		return "" + mTotalMeters / 10;
	}

	public String getPreviousDistance() {
		if (mPreviousKilometers > 0)
			return "" + mPreviousKilometers + "."
					+ getIntWithZero(mPreviousMeters, 3);
		return "" + mPreviousMeters;
	}

	public String getPriviousDistanceShort() {
		if (mPreviousKilometers > 0)
			return "" + mPreviousKilometers + "."
					+ getIntWithZero(mPreviousMeters / 10, 2);
		return "" + mPreviousMeters / 10;
	}

	public String getSpeedShort() {
		return "" + mSpeedKilometers + "." + mSpeedRemnat;
	}

	public String getGpsStatusShort() {
		return mGpsStatus ? "OK" : "--";
	}

	public String getPointNumberShort() {
		return "" + mPointNumber;
	}

	public String getStateShort() {
		return "" + mState;
	}

	public String getBatteryShort() {
		return "" + mBatteryLevel;
	}

}
